package com.beyondsoft.mcms.common;

import java.io.File;

public class ExcelHandlerFactory {

	public static ExcelImportService CreateExcelHandler(String excelName) {
		if (excelName == null || excelName.length() == 0 || excelName.lastIndexOf(".") == -1) {
			return null;
		}
		String strValue = excelName.substring(excelName.lastIndexOf(".") + 1);
		// excel2003
		if (strValue.equals("xls")) {
			return new ExcelImportServiceImplFor2003();
		} else if (strValue.equals("xlsx")) {
			// excel2007
			return new ExcelImportServiceImplFor2007();
		} else {
			return null;
		}
	}


	public static ExcelImportService CreateExcelHandler(File file) {
		String excelName = file.getName();
		if (excelName == null || excelName.length() == 0 || excelName.lastIndexOf(".") == -1) {
			return null;
		}
		String strValue = excelName.substring(excelName.lastIndexOf(".") + 1);
		// excel2003
		if (strValue.equals("xls")) {
			return new ExcelImportServiceImplFor2003();
		} else if (strValue.equals("xlsx")) {
			// excel2007
			return new ExcelImportServiceImplFor2007();
		} else {
			return null;
		}
	}
    
    /**
	 * Test
	 */
//	public static void main(String[] args) throws Exception {
//		for (Iterator iter = multipartRequest.getFileNames(); iter.hasNext();) {
//	
//			fieldName = (String) iter.next();
//			MultipartFilefile = (MultipartFile) multipartRequest.getFile(fieldName);
//			File file = request;
//			ExcelImportService excel = ExcelHandlerFactory.CreateExcelHandler(file.getOriginalFilename());
//			List<Map<String, Object>> mapList = excel.ImportExcel(file.getInputStream()).getReturnObj();
//		}
//	}
}
